package com.learn.lombok.lock;

import lombok.Locked;

import java.util.concurrent.locks.ReentrantLock;

public class LockEntity {
    private final ReentrantLock fieldLock = new ReentrantLock();
    private int value = 0;

    // 读琐
    @Locked.Read
    public int getValue() {
        return value;
    }

    // 写锁
    @Locked.Write
    public void setValue(int newValue) {
        value = newValue;
    }

    // 自定义使用锁（如果为空，不能与@Locked.Read、@Locked.Write同时使用）
    @Locked("fieldLock")
    public void foo2() {
        System.out.println("foo2");
    }
}
